var express = require('express');
var router = express.Router();
const addposition = require("../service/addposition.js");

/*引入multer模块*/
const path = require("path");
const multer = require("multer");
//配置multer
const storage = multer.diskStorage({
  // 上传文件保存的目标目录
  destination: function (req, file, cb) {
    cb(null, path.join(__dirname, "../public/images/upload/"));
  },
  // 上传文件保存的文件名
  filename: function (req, file, cb) {
    cb(null, file.fieldname + '-' + Date.now() + file.originalname.slice(file.originalname.lastIndexOf(".")))
  }
})

const upload = multer({ storage: storage })

/* GET users listing. */
router.get('/', function(req, res, next) {
  res.send('respond with a resource');
});


/*添加职位：post请求，路由仅仅只处理路由的业务，真正的登录业务在addposition里进行*/
router.post('/add',upload.single("logo"),addposition.add);
/*前端页面刷新查找全部职位：post请求，路由仅仅只处理路由的业务，真正的登录业务在addposition里进行*/
router.post('/find',addposition.find);
/*删除职位：post请求，路由仅仅只处理路由的业务，真正的登录业务在addposition里进行*/
router.post('/del',addposition.delete);
/*修改职位：post请求，路由仅仅只处理路由的业务，真正的登录业务在addposition里进行*/
router.post('/edit',upload.single("logo"),addposition.edit);



module.exports = router;
